<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<include file="__VIEW__/Common/header" />
	    <script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor1_4_3/ueditor.config.js"></script>
	    <script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor1_4_3/ueditor.all.min.js"></script>
	    <script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	    <!--上传插件uploadify的文件-->
		<script type="text/javascript" src="__STATIC__/uploadify/jquery-1.8.2.min.js"></script>
		<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
		<link href="__STATIC__/uploadify/uploadify.css" type="text/css" rel="stylesheet"></link>
	    <script type="text/javascript">
			//让上传按钮显示
			function gpicUploadifyShow(){
        		$('#file').uploadify({
                    'formData'     : {//POST数据
                        '<?php echo session_name();?>' : '<?php echo session_id();?>',
                    },
                    'fileTypeDesc' : '上传文件',//上传描述
                    'fileTypeExts' : '*.jpg;*.png;*.gif',
                    'swf'      : '__STATIC__/uploadify/uploadify.swf',
                    'uploader' : '{|U:"uploadList"}',
                    'buttonText':'选择文件',
                    'fileSizeLimit' : '2000KB',
                    'uploadLimit' : 1,//上传文件数
                    'width':65,
                    'height':25,
                    'multi': false,//是否多文件上传
                    'successTimeout':10,//等待服务器响应时间
                    'removeTimeout' : 0.2,//成功显示时间
                    'onUploadSuccess' : function(file, data, response) {
                    	//把变量转为json
                        data=$.parseJSON(data);
                        var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+data.url+"' style='width:200px;' class='img-thumbnail'/><a href='javascript:;' class='removeImg'>X</a><input type='hidden' name='gpic' value='"+data.path+"' /></li>";
                        $("#uploadList ul").prepend(li);
                        //让删除按钮消失
                        $('.uplodify-box').html('');
                    }
                });
	        }
			function uploadifyShow(){
				$('#pic').uploadify({
	               'formData'     : {//POST数据
	                   '<?php echo session_name();?>' : '<?php echo session_id();?>',
	               },
	               'fileTypeDesc' : '上传文件',//上传描述
	               'fileTypeExts' : '*.jpg;*.png;*.gif',
	               'swf'      : '__STATIC__/uploadify/uploadify.swf',
	               'uploader' : '{|U:"uploadPic"}',
	               'buttonText':'选择文件',
	               'fileSizeLimit' : '2000KB',
	               'uploadLimit' : 1000,//上传文件数
	               'width':65,
	               'height':25,
	               'successTimeout':10,//等待服务器响应时间
	               'removeTimeout' : 0.2,//成功显示时间
	               'onUploadSuccess' : function(file, data, response) {
	               	//把变量转为json
	                   data=$.parseJSON(data);
	                   var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+data.url+"' style='width:200px;' class='img-thumbnail'/><a href='javascript:;' class='removeImgpic'>X</a><input type='hidden' name='piclist[]' value='"+data.path+"' /></li>";
	                   $("#uploadListpic ul").prepend(li);
	               }
	           });
	       }
            $(function(){
            	//刷新页面让上传插件显示
            	gpicUploadifyShow();
            	uploadifyShow();
            	//点击x，隐藏图片，并且上传按钮显示
	  			$('.removeImg').live('click',function(){
	  				//获得当前图片的所在的li，让其消失
	  				$(this).parent('li').parent('ul').html("");
	  				//上传按钮显示
	  				$('.uplodify-box').html('<input id="file" type="file" multiple="false"><span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>');
	  				gpicUploadifyShow();
	  			});
	  			//点击x，隐藏图片，并且上传按钮显示
	  			$('.removeImgpic').live('click',function(){
	  				//获得当前图片的所在的li，让其消失
	  				$(this).parent('li').html("");
	  				uploadifyShow();
	  			});
	  			//ajax获得类型属性
	  			$("#cid").change(function(){
	  				var nowCid = $(this).val();
	  				if(nowCid == ""){
	  					$("#gg").html("");
  						$("#attr").html("");
  						$("#tid").val("");
  						return;
	  				}
	  				$.ajax({
	  					type:"post",
	  					url:"{|U:'getTypeAttr'}",
	  					data:{cid:nowCid},
	  					dataType:"json",
	  					success:function(data){
	  						$("#gg").html(data.ggStr);
	  						$("#attr").html(data.attrStr);
	  						$("#tid").val(data.tid);
	  					}
	  				});
	  			});
	  			//添加属性
	  			$(".addAttr").live('click',function(){
	  				var strEl = $(this).parent('td').parent('tr');
	  				var newStr = "<tr>"+strEl.html()+"</tr>";
	  				strEl.after(newStr);
	  				strEl.next().children("td").last().html("<a href='javascript:;' class='delAttr btn btn-sm btn-warning'>删除属性</a>");
	  			});
	  			//删除属性
	  			$(".delAttr").live('click',function(){
	  				$(this).parent('td').parent('tr').remove();
	  			});
            });
        </script>
        <style type="text/css">
	    ul li{list-style: none;}
	    #uploadList li{position: relative;}
	    a.removeImg{position: absolute;top: -10px;left: 190px;display: block;width: 20px;height: 20px;background: #FF0000;color: #FFF;border-radius: 50%;text-align: center;line-height: 20px;}
	    </style>
	</head>
	<body>
		<form action="" method="post">
		<div class="alert alert-success">添加商品</div>
		<div class="form-group">
			<label for="exampleInputEmail4">所属分类</label>
			<input type="hidden" name="tid" value="" id="tid" />
			<select name="cid" id="cid" class="form-control">
				<option value="">请选择</option>
				<foreach from="$cateData" key="$c" value="$cd">
					<option value="{$cd.cid}">{$cd._name}</option>
				</foreach>
			</select>
		</div>
		<div class="form-group">
			<label for="exampleInputEmail5">所属品牌</label>
			<select name="bid" class="form-control">
				<option value="">请选择</option>
				<foreach from="$brandData" key="$b" value="$bd">
					<option value="{$bd.bid}">{$bd.bname}</option>
				</foreach>
			</select>
		</div>
		<div class="form-group">
			<label for="exampleInputEmail1">商品名称</label>
			<input name="gname" id="exampleInputEmail1" class="form-control" type="text" required="" />
		</div>
		<div class="form-group">
			<label for="exampleInputEmail2">单位</label>
			<input name="gunit" id="exampleInputEmail2" class="form-control" type="text" required="" />
		</div>
		<div class="form-group">
			<label for="exampleInputEmail3">市场价</label>
			<input name="gmarketprice" id="exampleInputEmail3" class="form-control" type="text" required="" />
		</div>
		<div class="form-group">
			<label for="exampleInputEmail6">商城价</label>
			<input name="gshopprice" id="exampleInputEmail6" class="form-control" type="text" required="" />
		</div>
		<div class="form-group">
			<label for="exampleInputEmail7">点击数</label>
			<input name="gclick" value="0" id="exampleInputEmail7" class="form-control" type="text" required="" />
		</div>
		<div class="form-group">
			<label for="exampleInputEmail8">商品规格</label>
			<table class="table table-hover" id="gg" style="background: #CCCCCC;">
				
			</table>
		</div>
		<div class="form-group">
			<label for="exampleInputEmail9">商品属性</label>
			<table class="table table-hover" id="attr" style="background: #CCCCCC;">
				
			</table>
		</div>
		<div class="form-group">
			<label for="exampleInputEmail10">列表图</label>
			<div class="uploadFile">
			  	<!--这个div是放上传按钮的-->
			  	<div class="uplodify-box">
				  	<input id="file" type="file" multiple="false">
		            <span>类型: *.jpg,*.png,*.gif 大小: 2000KB 数量: 1</span>
			  	</div>
	            <div id="uploadList">
	                <ul>
	                </ul>
	            </div>
        	</div>
		</div>
		<div class="form-group">
			<label for="exampleInputEmail11">商品图册</label>
			<div class="uploadFile">
			  	<!--这个div是放上传按钮的-->
			  	<div class="uplodify-boxpic">
				  	<input id="pic" type="file" multiple="false">
		            <span>类型: *.jpg,*.png,*.gif 大小: 2000KB</span>
			  	</div>
	            <div id="uploadListpic">
	                <ul>
	                </ul>
	            </div>
        	</div>
		</div>
		<div class="form-group">
			<label onclick="setUe()">商品详细</label>
			<br />
			<script id="detail" type="text/plain" style="width:1024px;height:500px;" name="intro"></script>
	    	<script>
	    	ue.ready(function(){
	    		var detail = UE.getEditor('detail');
	    		detail.setHide();
	    	});
	    	var detShow = false;
        	function setUe(){
        		if(detShow){
        			UE.getEditor('detail').setHide();
        			detShow = false;
        		}else{
        			UE.getEditor('detail').setShow();
        			detShow = true;
        		}
        	}
	    	</script>
		</div>
		<div class="form-group">
			<label onclick="setUes()">售后服务</label>
			<br />
			<script id="service" type="text/plain" style="width:1024px;height:500px;" name="service"></script>
	    	<script>
	    	ue.ready(function(){
	    		var detail = UE.getEditor('service');
	    		detail.setHide();
	    	});
	    	var serviceShow = false;
        	function setUes(){
        		if(serviceShow){
        			UE.getEditor('service').setHide();
        			serviceShow = false;
        		}else{
        			UE.getEditor('service').setShow();
        			serviceShow = true;
        		}
        	}
	    	</script>
		</div>
		<button class="btn btn-primary btn-block" type="submit">确定添加</button>
		</form>
	</body>
</html>
